﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using TAMS;

namespace TAMS.Admin
{
    public partial class Admin_OfficeAdd : System.Web.UI.Page
    {
        MySqlConnection conn;
        MySqlCommand sqlCommand;
        MySqlDataReader readVals;
        string strProvider = Resource1.databaseConnection;

        protected void Page_Load(object sender, EventArgs e)
        {
            ((Menu)Master.FindControl("Menu1")).Items[5].Selected = true;
            Master.FindControl("ContentPlaceholder1").FindControl("Button2").Visible = false;
            Master.FindControl("ContentPlaceholder1").FindControl("Button3").Visible = false;
            Master.FindControl("ContentPlaceholder1").FindControl("Button4").Visible = false;

        }

        protected void Add_Click(object sender, EventArgs e)
        {
            /*Get info from textboxes*/

            string offCode = ID.Text;
            string name = Name.Text;
            string phoneNumber = PNO.Text;



            // Connect to the Database
            conn = new MySqlConnection(strProvider);
            conn.Open();

            string insertStaff = "INSERT "
                                 + "INTO Office "
                                 + "VALUES ( '" + offCode+ "', "  +"'" + name + "',"+ phoneNumber+ ")";
 

            sqlCommand = new MySqlCommand(insertStaff, conn);

            Boolean checker = false;
            try
            {
                readVals = sqlCommand.ExecuteReader();
                readVals.Close();

            }
            catch (MySqlException ex)
            {

                string msg = "Add Error: ";
                msg += ex.Message;
                ErrorLiteral.Text = msg;
                ErrorLiteral.Visible = true;
                checker = true;

            }

            if (!checker)
            {
                Response.Redirect("Admin_Office.aspx");
            }
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Admin_Office.aspx");
        }

    }
}